#pragma once

#include <functional>
#include <condition_variable>
// #include <mutex>
// #include <string>

#include "../utility/Noncopyable.h"
#include "../thread/Thread.h"

class EventLoop;

class EventLoopThread : Noncopyable
{
public:
    using ThreadInitCallback = std::function<void(EventLoop *)>;

    EventLoopThread(const ThreadInitCallback &cb = ThreadInitCallback{},
                    const std::string &name = "");
    ~EventLoopThread();

    EventLoop *startLoop();

private:
    void threadFunc();

    Thread thread_;
    // 用户EchoServer->TcpServer->EventLoopThreadPool->EventLoopThread
    // 注册的线程初始化回调，用户线程初始化回调可能未用到
    ThreadInitCallback callback_;
    EventLoop *loop_;
    bool isQuit_;
    std::mutex mtx_;
    std::condition_variable cond_;
};